<template>
  <div class="component-container">
    <el-card shadow="never">
      <el-form :model="value" :rules="rules" ref="houseConfigForm" label-width="130px" style="width: 80%" size="small">
        <el-form-item label="租期范围：" prop="title">
          <el-col :span="6">
            <el-form-item label="开始月份"  prop="startMonth" style="margin-left: -62px;font-weight: normal">
              <el-select v-model="value.startMonth" placeholder="请选择" clearable >
                <el-option
                  v-for="dict in dict.type.house_start_month"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结束月份" prop="endMonth" style="margin-left: -52px;font-weight: normal">
              <el-select v-model="value.endMonth" placeholder="请选择" clearable >
                <el-option
                  v-for="dict in dict.type.house_end_month"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="短租费用（非必填）：" >
          <el-input v-model="value.shortRent">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="长租费用：" prop="money">
          <el-input v-model="value.money">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="押金：" prop="deposit">
          <el-input v-model="value.deposit">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="管理/服务费：" prop="serviceMoney">
          <el-input v-model="value.serviceMoney">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="是否收中介费：" prop="isagency">
          <el-col :span="5">
            <el-radio-group v-model="value.isagency">
              <el-radio :label="1">否</el-radio>
              <el-radio :label="2">是</el-radio>
            </el-radio-group>
          </el-col>
          <el-col :span="19">
            <el-input v-model="value.agencyMoney">
              <template slot="append">元</template>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="支付方式：" prop="payType">
          <el-select v-model="value.payType" placeholder="请选择支付方式" clearable>
            <el-option
              v-for="dict in dict.type.house_pay_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="租客要求：" prop="requirement">
          <el-checkbox-group v-model="selectRequirement">
            <el-checkbox
              v-for="dict in dict.type.house_requirement"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="显示状态：" prop="isshow">
          <el-radio-group v-model="value.isshow">
            <el-radio
              v-for="dict in dict.type.sys_show_list"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="佣金比例：" prop="commission">
          <el-input v-model="value.commission" placeholder="请输入佣金比例纯数字">
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
        <el-form-item style="text-align: center">
          <el-button size="medium" @click="handlePrev">上一步，填写房屋配置</el-button>
          <el-button type="primary" size="medium" @click="handleFinishCommit">完成，提交信息</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: "HouseCostDetail",
    dicts: ['house_start_month','house_end_month','house_pay_type','house_requirement','sys_show_list'],
    props: {
      value: Object,
      isEdit: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        rules: {}
      }
    },
    computed: {
      // 选中的租客要求
      selectRequirement: {
        get() {
          let list = [];
          if (this.value.requirement === undefined || this.value.requirement == null || this.value.requirement === '') return list;
          let ids = this.value.requirement.split(',');
          for (let i = 0; i < ids.length; i++) {
            list.push((ids[i]));
          }
          return list;
        },
        set(newValue) {
          let requirement = '';
          if (newValue != null && newValue.length > 0) {
            for (let i = 0; i < newValue.length; i++) {
              requirement += newValue[i] + ',';
            }
            if (requirement.endsWith(',')) {
              requirement = requirement.substr(0, requirement.length - 1)
            }
            this.value.requirement = requirement;
          } else {
            this.value.requirement = null;
          }
        }
      }
    },
    methods: {
      handlePrev(){
        this.$emit('prev')
      },
      handleFinishCommit(){
        this.$emit('finishCommit',this.isEdit);
      }
    }
  }
</script>
